package threading;
//必须要先执行 wait ，然后 notify 才有效
public class ThreadDemo14 {
    public static void main(String[] args) throws InterruptedException {
        Object locker = new Object();
        Thread t1 = new Thread(()->{
               try {
                   System.out.println("wait 开始");
                   synchronized (locker){
                       locker.wait();
                   }
                   System.out.println("wait 结束");
               }catch (InterruptedException e){
                   e.printStackTrace();
               }
        });
        t1.start();

        Thread.sleep(1000);

        Thread t2 = new Thread(()->{
            synchronized (locker){
                System.out.println("notify 开始");
                locker.notify();
                System.out.println("notify 结束");
            }
        });
        t2.start();
    }
}
